package com.jniu.customviewprogram.actrivity;

import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MenuItem;

import com.jniu.customviewprogram.R;
import com.jniu.customviewprogram.adapter.NoScrollAdapter;
import com.jniu.customviewprogram.view.NoScrollViewPager;

public class NoScrollViewPagerActivity extends AppCompatActivity implements BottomNavigationView.OnNavigationItemSelectedListener {

    private NoScrollViewPager viewPager;
    private BottomNavigationView navigationView;

    public static final int[] imgs = {R.mipmap.ic_launcher , R.mipmap.ic_launcher , R.mipmap.ic_launcher , R.mipmap.ic_launcher};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_no_scroll_view_pager);

        initView();
    }

    private void initView() {
        viewPager = (NoScrollViewPager) findViewById(R.id.viewPager);
        viewPager.setAdapter(new NoScrollAdapter(this,imgs));
        navigationView = (BottomNavigationView) findViewById(R.id.bottomNavigationView);
        navigationView.setOnNavigationItemSelectedListener(this);
    }

    @Override
    public boolean onNavigationItemSelected(@NonNull MenuItem item) {
        switch (item.getItemId()) {
            case R.id.menu_bottom_1:
                viewPager.setCurrentItem(0);
                break;
            case R.id.menu_bottom_2:
                viewPager.setCurrentItem(1);
                break;
            case R.id.menu_bottom_3:
                viewPager.setCurrentItem(2);
                break;
            case R.id.menu_bottom_4:
                viewPager.setCurrentItem(3);
                break;
        }
        return true;
    }
}
